package com.panda.admin.result;

import lombok.Data;

/**
 * author: tcy
 * createDate: 2022/10/8
 * description:
 */
@Data
public class Result<T> {

    /**
     * 状态编码
     */
    private int code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应数据
     */
    private T data;

    /**
     * 成功响应
     */
    public static <T>Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultEnums.SUCCESS.getCode());
        result.setMessage(ResultEnums.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

    /**
     * 失败响应
     */
    public static <T>Result<T> fail(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultEnums.Fail.getCode());
        result.setMessage(ResultEnums.Fail.getMsg());
        result.setData(data);
        return result;
    }

    /**
     * 获取code
     * @return
     */
    public int getCode(){
        return this.code;
    }

    /**
     * 获取message
     * @return
     */
    public String getMessage() {
        return message;
    }

    /**
     * 获取data
     * @return
     */
    public T getData() {
        return data;
    }

}
